/*
 * @Descripttion: 
 * @version: 
 * @Author: Ansel
 * @Date: 2020-03-04 00:25:43
 * @LastEditors: Ansel
 * @LastEditTime: 2020-05-15 16:05:44
 */ 
// function jsonp(url,params,cb){
//     return new Promise((resolve,reject) =>{
//         let script = document.createElement("script");
//         let p = {...params,cb};
//         let arrs = [];
//         for(let prop in p){
//             arrs.push(`${prop}=${p[prop]}`);
//         }
//         script.src = `${url}?prod=pc&${arrs.join("&")}`;
//         window[cb] = function(data){
//             resolve(data);
//             document.body.removeChild(script);
//         }
//         document.body.append(script);
//     })
// }

// export {jsonp}

// 将回调方法定义到一个命名空间上，使用完成后删除。如下：
// window.name_space = {};
// name_space.foo = function() {
//   ...
//   delete name_space.foo;
// };
function jsonp(url,params,cb){
    return new Promise((resolve,reject)=>{
        let script = documnet.createElement("script");
        let p = {...params,cb};
        let arr = [];
        for(let props in p){
            arr.push(`${props} = ${p[props]}`);
        }
        script.src = `${url}?${arr.join("&")}`;
        window[cb] = function(data){
            resolve(data);
            document.removeChild(script);
        }
        document.body.append(script);
    })
}
